package org.edu.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "MAIL", catalog="SCHOOL")
public class Mail implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long mail_id;
	private Set<User> users = new HashSet<>();
	private String subject;
	private String messages;
	private Boolean is_read;
	private Date date;
	private Boolean status_mail;

	@Id
	@GeneratedValue
	@Column(name = "MAIL_ID")
	public Long getMail_id() {
		return mail_id;
	}

	public void setMail_id(Long mail_id) {
		this.mail_id = mail_id;
	}

	@ManyToMany
	@JoinTable(name = "JOIN_USER_MAIL", joinColumns = { @JoinColumn(name = "MAIL_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@Column(name = "SUBJECT", length = 50)
	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	@Column(name = "MESSAGES", length = 500)
	public String getMessages() {
		return messages;
	}

	public void setMessages(String messages) {
		this.messages = messages;
	}

	@Column(name = "IS_READ")
	public Boolean getIs_read() {
		return is_read;
	}

	public void setIs_read(Boolean is_read) {
		this.is_read = is_read;
	}

	@Column(name = "DATE")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Column(name = "STATUS_MAIL")
	public Boolean getStatus_mail() {
		return status_mail;
	}

	public void setStatus_mail(Boolean status_mail) {
		this.status_mail = status_mail;
	}

	public Mail() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((is_read == null) ? 0 : is_read.hashCode());
		result = prime * result + ((mail_id == null) ? 0 : mail_id.hashCode());
		result = prime * result
				+ ((messages == null) ? 0 : messages.hashCode());
		result = prime * result
				+ ((status_mail == null) ? 0 : status_mail.hashCode());
		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Mail other = (Mail) obj;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (is_read == null) {
			if (other.is_read != null)
				return false;
		} else if (!is_read.equals(other.is_read))
			return false;
		if (mail_id == null) {
			if (other.mail_id != null)
				return false;
		} else if (!mail_id.equals(other.mail_id))
			return false;
		if (messages == null) {
			if (other.messages != null)
				return false;
		} else if (!messages.equals(other.messages))
			return false;
		if (status_mail == null) {
			if (other.status_mail != null)
				return false;
		} else if (!status_mail.equals(other.status_mail))
			return false;
		if (subject == null) {
			if (other.subject != null)
				return false;
		} else if (!subject.equals(other.subject))
			return false;
		return true;
	}
	
}
